/* -----------------------------------------------------------------------
 *Lindsay Ergenekan 
 * Demonstration of how to write unit tests for dominion-base
 * 
 * This unit tests whether each player is playing the correct number of hands per round and the correct number of players
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i;
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
	int hand[MAX_HAND];
	int new_hand[MAX_HAND]; //variable to test the shuffle]
	int howManyMatched = 0;
    struct gameState G;
    int maxHandCount = 5;
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int silvers[MAX_HAND];
    int golds[MAX_HAND];
	
    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        silvers[i] = silver;
        golds[i] = gold;
    }


    printf ("TESTING updateCoins():\n");
    for (p = 0; p < numPlayer; p++)
    {
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
            for (bonus = 0; bonus <= maxBonus; bonus++)
            {
#if (NOISY_TEST == 1)
                printf("Player %d played. \n", p);
#endif

                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
				for (int i = 0; i <= MAX_HAND; ++i)
					{hand[i] = G.hand[p][i];}
					
				shuffle(p, &G);
				
				for (int i = 0; i <= MAX_HAND; ++i)
					{new_hand[i] = G.hand[p][i];}
					
				for (int i = 0; i <= MAX_HAND; ++i)
					{if (hand[p] != new_hand[p])
						{++howManyMatched;}
					}
				
				int percentageMatch = (howManyMatched/(sizeof(G.hand[p]) ));
				
				if (percentageMatch < .15)
			
            printf("test failed in 1st portion (%d)",i) ;
	
#if (NOISY_TEST == 1)
                printf("player %d hand was successfully shuffled once", p);
#endif
				shuffle(p, &G);

				for (int i = 0; i <= MAX_HAND; ++i)
					{hand[i] = G.hand[p][i];}
					
				shuffle(p, &G);
				
				for (int i = 0; i <= MAX_HAND; ++i)
					{new_hand[i] = G.hand[p][i];}
					
				for (int i = 0; i <= MAX_HAND; ++i)
					{if (hand[p] != new_hand[p])
						{++howManyMatched;}
					}
				
				percentageMatch = (howManyMatched/(sizeof(G.hand[p])));
				
				if (percentageMatch < .15)
				printf("test failed in 2nd test (%d)",i) ;
 
#if (NOISY_TEST == 1)
                printf("player %d hand was successfully shuffled twice", p);
#endif
		}
     
    }
    printf("All tests passed!\n");
}

    return 0;
}
